package cn.edu.neusoft.wuguangsheng.market.activity;

import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.market.R;
import cn.edu.neusoft.wuguangsheng.market.adapter.SearchAdapter;
import cn.edu.neusoft.wuguangsheng.market.bean.FoodByShopBean;
import cn.edu.neusoft.wuguangsheng.market.listener.ListListener;
import cn.edu.neusoft.wuguangsheng.market.model.SearchModel;

public class SearchActivity extends BaseActivity {
    RecyclerView recyclesearch;
    String search;
    private List<FoodByShopBean> items;
    @Override
    void initView() {
        setLayout_file(R.layout.activity_search);
        recyclesearch=(RecyclerView)findViewById(R.id.recyclesearch);
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(SearchActivity.this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclesearch.setLayoutManager(linearLayoutManager);
        SearchModel searchModel=new SearchModel();
        search=getIntent().getStringExtra("search");
        searchModel.searchIface(search,listListener);
    }

    @Override
    void initEvent() {

    }

    @Override
    void initDate() {

    }

    ListListener<FoodByShopBean> listListener=new ListListener<FoodByShopBean>() {
        @Override
        public void onResponse(List<FoodByShopBean> list) {
            items=list;

            if (items==null){
                Toast.makeText(SearchActivity.this,"没有查询到你要搜索的菜品",Toast.LENGTH_SHORT).show();
            }else{

                //CommentsAdapter commentsAdapter=new CommentsAdapter(UserAllCommentActivity.this,items,R.layout.commentscard);
                SearchAdapter searchAdapter=new SearchAdapter(SearchActivity.this,items,R.layout.card);
                recyclesearch.setAdapter(searchAdapter);
                recyclesearch.setItemAnimator(new DefaultItemAnimator());
            }
        }

        @Override
        public void onFail(String msg) {

        }
    };
}
